#include <iostream>
#include <stdio.h>
#include <stack>
using namespace std;

void swap(char* str, int left, int right)
{
    while (left < right)
    {
        char sw = str[left];
        str[left] = str[right];
        str[right] = sw;
        left++;
        right--;
    }
}

int main() {
    char str[101] = { 0 };
    gets_s(str);
    int n = strlen(str);
    swap(str, 0, n - 1);
    for (int left = 0, right = 0; right < n; right++)
    {
        if (str[right + 1] == ' ' || str[right + 1] == '\0')
        {
            swap(str, left, right);
            left = right + 2;
        }
    }
    printf("%s\n", str);
    return 0;
}

class Solution {
public:
    bool CheckPermutation(string s1, string s2) {
        int n1 = s1.size();
        int n2 = s2.size();
        if (n1 != n2)
        {
            return false;
        }
        int str1[26] = { 0 };
        for (auto s : s1)
        {
            str1[s - 'a']++;
        }
        int ret = 0;
        int str2[26] = { 0 };
        for (auto s : s2)
        {
            str2[s - 'a']++;
            if (str2[s - 'a'] <= str1[s - 'a'])
            {
                ret++;
            }
        }
        if (ret == n2)
        {
            return true;
        }
        return false;
    }
};

int main() {
    int num = 0;
    cin >> num;
    while (num--)
    {
        string s;
        cin >> s;
        int n = s.size();
        if (n >= 10)
        {
            cout << s[0] << n - 2 << s[n - 1] << endl;
        }
        else
        {
            cout << s << endl;
        }
    }
    return 0;
}

class Solution {
public:
    string replaceSpaces(string S, int length) {
        string s1;
        for (int i = 0; i < length;)
        {
            if (S[i] == ' ')
            {
                s1 += '%';
                s1 += '2';
                s1 += '0';
            }
            else
            {
                s1 += S[i];
            }
            i++;
        }
        S = s1;
        return S;
    }
};

class Solution {
public:
    string compressString(string S) {
        int n = S.size();
        string s1;
        int i = 0;
        stack<int> st;
        while (i < n)
        {
            int sum = 1;
            while (i < n && S[i] == S[i + 1])
            {
                i++;
                sum++;
            }
            s1 += S[i];
            while (sum)
            {
                st.push(sum % 10);
                sum /= 10;
            }
            while (!st.empty())
            {
                s1 += (st.top() + '0');
                st.pop();
            }
            i++;
        }
        if (n > s1.size())
        {
            S = s1;
        }
        return S;
    }
};

class Solution {
public:
    int exchangeBits(int num) {
        return ((num & 0xaaaaaaaa) >> 1) | ((num & 0x55555555) << 1);
    }
};